package com.example.wordcardjavaproject.utils;

import com.example.wordcardjavaproject.bean.entity.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUserIdUtils {
    public static Long getUserId() {
        //获取token 解析获取userid
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        //获取userid
        return loginUser.getUser().getId();
    }
}
